<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>传递给脚本的参数数目</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="reserved.variables.httpresponseheader.html">« $http_response_header</a></li>
      <li style="float: right;"><a href="reserved.variables.argv.html">$argv »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="reserved.variables.html">预定义变量</a></li>
    <li>传递给脚本的参数数目</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="reserved.variables.argc" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">$argc</h1>
  <p class="refpurpose"><span class="refname">$argc</span> &mdash; <span class="dc-title">传递给脚本的参数数目</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-reserved.variables.argc-description">
  <h3 class="title">说明</h3>
  <p class="para">
   包含当运行于<a href="features.commandline.html" class="link">命令行</a>下时传递给当前脚本的参数的数目。
  </p>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <span class="simpara">
    脚本的文件名总是作为参数传递给当前脚本，因此 <var class="varname">$argc</var> 的最小值为 <code class="literal">1</code>。
   </span>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <span class="simpara">
    这个变量仅在 <a href="ini.core.html#ini.register-argc-argv" class="link">register_argc_argv</a> 打开时可用。
   </span>
  </p></blockquote>
 </div>

 
 <div class="refsect1 examples" id="refsect1-reserved.variables.argc-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="variable.argc.basic">
    <p><strong>示例 #1 <var class="varname">$argc</var> 范例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$argc</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>
     当使用这个命令执行: php script.php arg1 arg2 arg3
    </p></div>
    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
int(4)
</pre></div>
    </div>
   </div>
  </p>
 </div>

 

 <div class="refsect1 notes" id="refsect1-reserved.variables.argc-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    也可以在 <var class="varname"><a href="reserved.variables.server.html" class="classname">$_SERVER['argc']</a></var> 中获取。
   </p>
  </p></blockquote>
 </div>


<div class="refsect1 seealso" id="refsect1-reserved.variables.argc-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.getopt.html" class="function" rel="rdfs-seeAlso">getopt()</a> - 从命令行参数列表中获取选项</span></li>
    <li class="member"><a href="reserved.variables.argv.html" class="link"><var class="varname"><a href="reserved.variables.argv.html" class="classname">$argv</a></var></a></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>